import type { PageResult } from '#/type/base_beans';
import type { SysRoleReq, SysRoleResp } from '#/type/sys_role';

import { requestClient } from '#/api/request';

const API_PREFIX = '/sys/role';

export async function getRoleByIdApi(id: string) {
  return requestClient.get<SysRoleResp>(`${API_PREFIX}/get_by_id/${id}`);
}

export async function getRoleListByIdsApi(ids: Array<string>) {
  return requestClient.get<Array<SysRoleResp>>(`${API_PREFIX}/get_by_ids`, {
    params: { ids },
  });
}

export async function getRoleListApi(params: SysRoleReq) {
  return requestClient.get<Array<SysRoleResp>>(`${API_PREFIX}/list`, {
    params,
  });
}

export async function getRolePageApi(params: SysRoleReq) {
  return requestClient.get<PageResult<SysRoleResp>>(`${API_PREFIX}/page`, {
    params,
  });
}

export async function createRoleApi(data: SysRoleReq) {
  return requestClient.post<Promise<void>>(`${API_PREFIX}/create`, data);
}

export async function editRoleApi(data: SysRoleReq) {
  return requestClient.put<Promise<void>>(`${API_PREFIX}/edit`, data);
}

export async function createEditRoleApi(data: SysRoleReq) {
  return requestClient.post<Promise<void>>(`${API_PREFIX}/create_edit`, data);
}

export async function deleteRoleApi(ids: Array<string>) {
  return requestClient.delete<Promise<void>>(`${API_PREFIX}/delete`, {
    params: { ids },
  });
}
